/**
  ******************************************************************************
  * @file           : motor.h
  * @brief          : Header for motor.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *	Created by Chen Lu in 20210504
  *
  ******************************************************************************
  */

#ifndef __MOTOR_H
#define	__MOTOR_H

#include "main.h"

#define MOTOR_ERROR	0
#define MOTOR_OK	1

#define CNT_FREQ	1000000					//timer count frequency

#define MOTOR_EN	MOTOR_EN_Pin
#define MOTOR_X_DIR	MOTOR_X_DIR_Pin
#define MOTOR_Y_DIR	MOTOR_Y_DIR_Pin
#define MOTOR_Z_DIR	MOTOR_Z_DIR_Pin

#define SUB_DIVISION	16						//subdivision
#define	STEP_ANGLE		(1.8 / SUB_DIVISION)	//step angle, unit: degree

typedef struct{
	uint8_t id;
	uint8_t direction;
	uint16_t speed;
}TiMotor;

TiMotor * motor_open(uint8_t id);
uint8_t motor_close(TiMotor* motor);
uint8_t motor_write(TiMotor* motor,uint8_t direction,uint16_t speed);
uint8_t motor_start(TiMotor* motor);
uint8_t motor_stop(TiMotor* motor);
uint8_t motor_init();

#endif /*__MOTOR_H */
